//
//  VISTASettingVC.m
//  VISTA看天下
//
//  Created by  on 15/12/2.
//  Copyright © 2015年 . All rights reserved.
//

#import "VISTASettingVC.h"
#import "VISTASettingMenu.h"
#import "SettingAboutVC.h"
#import "SettingAppVC.h"
#import "SettingFontVC.h"
#import "SettingLoginVC.h"
#import "SettingSendingVC.h"
#import "SettingShareVC.h"
#import "SettingStarVC.h"
//static NSString *font;
@interface VISTASettingVC()
{
    
}
@property (nonatomic, strong)NSMutableArray *dataSorceArray;

@end
@implementation VISTASettingVC


- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self configNavi];
    [self createMenu];
}

/**
 *  设置导航栏
 */
- (void)configNavi
{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NAVI"] forBarMetrics:UIBarMetricsDefault];
    
    //定制导航栏左按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 50, 32);
    [leftButton setImage:[UIImage imageNamed:@"返回_1"] forState:UIControlStateNormal];
    [leftButton setImage:[UIImage imageNamed:@"返回_2"] forState:UIControlStateHighlighted];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftItem;
    //导航栏标题
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
    titleLabel.text = @"设置";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
}
- (void)back
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)createMenu
{
    VISTASettingMenu *setting = [[VISTASettingMenu alloc]initWithFrame:CGRectMake(20, 76, self.view.frame.size.width-40, 40*9)];
    setting.delegate = self;
    
    [self.view addSubview:setting];
}
#pragma SettingBarDelegate
-(void)settingBar:(VISTASettingMenu *)settingBar didClickButton:(UIButton *)button WithButtonIndex:(NSInteger)index
{
    NSLog(@"index = %ld",(long)index);
    switch (index) {
        case 0:
        {
            SettingFontVC *fontVC = [[SettingFontVC alloc]init];
            fontVC.title =settingBar.titleArray[index];
            [self.navigationController pushViewController:fontVC animated:YES];
        }
            break;
        case 1:
        {
            SettingStarVC *starVC = [[SettingStarVC alloc]init];
            starVC.title =settingBar.titleArray[index];
            [self.navigationController pushViewController:starVC animated:YES];
        }
            break;
        case 2:
        {
            SettingShareVC *shareVC = [[SettingShareVC alloc]init];
            shareVC.title =settingBar.titleArray[index];
            [self.navigationController pushViewController:shareVC animated:YES];
        }
            break;
        case 3:
        {
            SettingLoginVC *loginVC = [[SettingLoginVC alloc]init];
            loginVC.title =settingBar.titleArray[index];
            [self.navigationController pushViewController:loginVC animated:YES];
        }
            break;
        case 4:
        {
            settingBar.isSending = !settingBar.isSending;
            if (settingBar.isSending) {
                settingBar.switchImageView.image = [UIImage imageNamed:@"关.png"];
            }else{
                settingBar.switchImageView.image = [UIImage imageNamed:@"开.png"];
            }
        }
            break;
        case 5:
        {
            SettingSendingVC *sendingVC = [[SettingSendingVC alloc]init];
            sendingVC.title =settingBar.titleArray[index];
            [self.navigationController pushViewController:sendingVC animated:YES];
        }
            break;
        case 6:
        {
            SettingAboutVC *aboutVC = [[SettingAboutVC alloc]init];
            aboutVC.title =settingBar.titleArray[index];
            [self.navigationController pushViewController:aboutVC animated:YES];
        }
            break;
        case 7:
        {
            SettingAppVC *appVC = [[SettingAppVC alloc]init];
            appVC.title =settingBar.titleArray[index];
            [self.navigationController pushViewController:appVC animated:YES];
        }
            break;
        case 8:
            
            break;
        default:
            break;
    }
}

#pragma mark tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSorceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuseID = @"settingID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
        
    }
    
    return cell;
}

@end
